<template>
    <view class="withdrawals-setting">
        <u-cell-group>
            <u-field v-model="setWithdrawalsForm.member_name" label="户名:" placeholder="请输入户名"></u-field>
            <u-field v-model="setWithdrawalsForm.bank_name" label="所属银行:" placeholder="请输入所属银行"></u-field>
            <u-field v-model="setWithdrawalsForm.opening_num" label="开户行号:" placeholder="请输入开户行号"></u-field>
            <u-field v-model="setWithdrawalsForm.bank_card" label="银行卡号:" placeholder="请输入银行卡号"></u-field>
        </u-cell-group>
        <view class="big-btn" @click="handleReserveWithdrawalsParams">
            <view class="btn">
                <text>保存设置</text>
            </view>
        </view>
    </view>
</template>

<script>
    import * as API_Distribution from '@/api/distribution.js'
	export default {
		data() {
			return {
                /** 申请表单 */
                setWithdrawalsForm: {
                    /** 户名 */
                    member_name: '',
                    /** 银行名称 */
                    bank_name: '',
                    /** 开户行号 */
                    opening_num: '',
                    /** 银行卡号 */
                    bank_card: ''
                }
			};
		},
        onLoad() {
            this.getWithdrawalsParams()
        },
        methods: {
            /** 获取提现设置 */
            getWithdrawalsParams() {
                API_Distribution.getWithdrawalsParams().then(response => {
                    this.setWithdrawalsForm = { ...response }
                })
            },
            /** 保存设置 */
            handleReserveWithdrawalsParams() {
                const { member_name, bank_name, opening_num, bank_card } = this.setWithdrawalsForm
                if (!member_name) {
                    this.$u.toast('户名不能为空')
                    return
                } else if (member_name.length >= 20) {
                    this.$u.toast('户名长度最多为20个字符')
                    return
                }
                if (!bank_name) {
                    this.$u.toast('所属银行不能为空')
                    return
                } else if (bank_name.length >= 20) {
                    this.$u.toast('所属银行长度最多为20个字符')
                    return
                }
                if (!opening_num) {
                    this.$u.toast('开户行号不能为空')
                    return
                } else if (opening_num.length >= 20) {
                    this.$u.toast('开户行号长度最多为20个字符')
                    return
                } else if (!this.$u.test.digits(opening_num)) {
                    this.$u.toast('开户行号必须为数字')
                    return
                }
                if (!bank_card) {
                    this.$u.toast('银行卡号不能为空')
                    return
                } else if (bank_card.length >= 20) {
                    this.$u.toast('银行卡号长度最多为20个字符')
                    return
                } else if (!this.$u.test.digits(bank_card)) {
                    this.$u.toast('银行卡号必须为数字')
                    return
                }
                API_Distribution.reserveWithdrawalsParams(this.setWithdrawalsForm).then(() => {
                    this.$u.toast('保存成功')
                })
            }
        }
	}
</script>

<style lang="scss" scoped>
    
</style>
